package com.lbs.jiepiaisi.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lbs.jiepiaisi.R;
import com.lbs.jiepiaisi.bean.MyEquipmentData;

import java.util.List;

/**
 *
 * 时间：2017/7/1 10:44
 * 作用：全部设备适配器
 */

public class PlatformListAllAdapter extends BaseAdapter {
    private List<MyEquipmentData> contacts;
    private int resource;
    private Context context;

    public  PlatformListAllAdapter(Context context, List<MyEquipmentData> contacts){
        this.context=context;
        this.contacts=contacts;
    }

    /**此方法用户返回数据的个数*/
    @Override
    public int getCount() {
        return contacts.size();
    }

    /**根据位置返回item对象对应的数据*/
    @Override
    public Object getItem(int position) {
        return contacts.get(position);
    }
    /**根据位置返回item对象对应的数据*/
    @Override
    public long getItemId(int position) {
        return position;
    }

    /**
     * 每显示一个item，此方法就会调用一次。
     */
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh=null;
        if(convertView==null){
            convertView=View.inflate(context, R.layout.list_item_platform_list_all, null);
            vh=new ViewHolder();
            vh.imageView=(ImageView)convertView.findViewById(R.id.item_image);
            vh.nameTV=(TextView)convertView.findViewById(R.id.item_name);
            vh.numTV=(TextView)convertView.findViewById(R.id.item_num);
            vh.dataTV=(TextView)convertView.findViewById(R.id.item_date);
            convertView.setTag(vh);
        }else{
            vh=(ViewHolder)convertView.getTag();
        }
        //数据
        MyEquipmentData c=contacts.get(position);
        //判断状态设置图片
        if(c.getState()==0){
            vh.imageView.setImageResource(R.mipmap.online_device);
        }else {
            vh.imageView.setImageResource(R.mipmap.offline_device);
        }
        vh.nameTV.setText(c.getName());
        vh.numTV.setText(c.getNum());
        vh.dataTV.setText(c.getContent());

        return convertView;
    }

    class ViewHolder{
        ImageView imageView;
        TextView nameTV;
        TextView numTV;
        TextView dataTV;
    }
}
